﻿<%@page contentType="text/html;charset=utf-8"%>
<%request.setCharacterEncoding("utf-8");%>
<%@page import="java.sql.*"%>
        <%
                String name = request.getParameter("name");
                String address = request.getParameter("address");
                String telephone = request.getParameter("telephone");
                int age = Integer.parseInt(request.getParameter("age"));
                String gender = request.getParameter("gender");

                Class.forName("com.mysql.jdbc.Driver");

                String url = "jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=utf8";
                String username = "root";
                String password = "6473";

                Connection conn = DriverManager.getConnection(url, username,
                                password);

                String sql = "insert into namecard(name,address,telephone,age,gender) values (?,?,?,?,?);";
                PreparedStatement pstmt = conn.prepareStatement(sql);

                pstmt.setString(1, name);
                pstmt.setString(2, address);
                pstmt.setString(3, telephone);
                pstmt.setInt(4, age);
                pstmt.setString(5, gender);

                pstmt.executeUpdate();
        %>



